package com.vm.utils;

import com.vm.activity.UpdateDialog;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Message;

public class ConnectManager {
	// static boolean isDownload = false;
	public static Handler mainHandler;

	public static void isDownload(Context context) {
		ConnectivityManager connManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo mWifi = connManager
				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		if (mWifi.isConnected()) {
			// isDownload = true;
			if (mainHandler != null) {
				Message message = new Message();
				message.what = 10;
				mainHandler.sendMessage(message);
			}
			// 不是WIFI情况下，提醒是否继续下载
		} else {
			final UpdateDialog dialog = new UpdateDialog(context, "温馨提示",
					"您在非WIFI环境下,是否下载？", "确认下载", "稍后再说", "");
			dialog.getWindow().setBackgroundDrawableResource(
					android.R.color.transparent);
			dialog.setCanceledOnTouchOutside(false);
			dialog.show();
			dialog.setClicklistener(new UpdateDialog.ClickListenerInterface() {

				@Override
				public void doConfirm() {
					// isDownload = true;
					if (mainHandler != null) {
						Message message = new Message();
						message.what = 10;
						mainHandler.sendMessage(message);
					}
					dialog.dismiss();
				}

				@Override
				public void doCancel() {
					// TODO Auto-generated method stub
					// isDownload = false;
					dialog.dismiss();
				}
			});
		}
		// return isDownload;
	}
}